package com.framework.core.satoken;

import cn.dev33.satoken.stp.StpInterface;
import com.framework.core.common.bo.SysRoleBO;
import com.framework.core.util.SecurityUtil;
import com.google.common.collect.Lists;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 自定义SaToken权限验证
 *
 * @author Kevin
 */
@Component
public class CustomStpInterface implements StpInterface {
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return Lists.newArrayList(SecurityUtil.getLoginUser().getPermissions());
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return SecurityUtil.getLoginUser().getSysUser().getRoles().stream().map(SysRoleBO::getRoleCode).collect(Collectors.toList());
    }
}
